package com.dao;

import com.database.common.Service;
import com.database.db.BaseDao;
import com.pojo.Account;

import java.util.Map;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-02-28.
 *
 * @author zhoufy
 */
@Service
public class AccountDaoImpl extends BaseDao implements AccountDao {


    @Override
    public Account getAccountByAccountNo(String accountNo) {

        String sql = "select * from account where accountNo = ? ";
        Map<String, Object> map = queryForMap(sql, new Object[]{accountNo});
        Account account = new Account();
        account.setAccountNo(accountNo);
        account.setUsername(map.get("userName").toString());
        account.setMoney(Integer.parseInt(map.getOrDefault("money", "0").toString()));

        return account;
    }

    @Override
    public int updateAccountInfoByAccountNo(Account account) {

        String sql = "update account set money = ? where accountNo = ? ";
        int res = executeSql(sql, new Object[]{account.getMoney(), account.getAccountNo()});
        return res;

    }
}
